<template>
  <div class="dashboard-editor-container" v-loading.fullscreen.lock="fullscreenLoading">
    <div style="width: 100%;">
      <el-row :gutter="10">
        <el-col  :xs="8" :sm="6" :md="4" :lg="3" >
          <el-button @click="getDataList"><i class="el-icon-refresh"/>
            {{$t('v520.refreshData')}}
          </el-button>
        </el-col>
        <el-col  :xs="8" :sm="6" :md="4" :lg="3" >
          <el-button type="primary" @click="showCreate(1)">
            <i class="el-icon-plus"/>
            {{$t('v520.createTask')}}
          </el-button>
        </el-col>
        <el-col  :xs="8" :sm="6" :md="4" :lg="3" >
          <el-button type="primary" @click="showCreate(2)">
            <i class="el-icon-plus"/>
            分步拉群
          </el-button>
        </el-col>
        <el-col  :xs="8" :sm="6" :md="4" :lg="3" >
          <el-button type="primary" @click="showCreate(3)">
            <i class="el-icon-plus"/>
            建立批量拉群
          </el-button>
        </el-col>
        <el-col  :xs="8" :sm="6" :md="4" :lg="3" >
          <el-button type="primary" @click="showCreate(4)">
            <i class="el-icon-plus"/>
            建立批量分步拉群
          </el-button>
        </el-col>
      </el-row>
    </div>
    <div v-if="selectIds.length > 0" style="margin-top: 15px;">
      <el-button type="success" size="mini" @click="batchReceipt()" round>
        <i class="wshub wshub-a-kuozhanicon_huaban1fuben5"></i>
        批量导出回执
      </el-button>
      <el-button type="success" size="mini" @click="batchPullData()" round>
        <i class="wshub wshub-a-kuozhanicon_huaban1fuben5"></i>
        批量导出群料子
      </el-button>
    </div>
    <el-table
      :data="tableData"
      style="width: 100%"
      @selection-change="handleSelectionChange"
    >
      <el-table-column
        type="selection"
        width="55">
      </el-table-column>
      <el-table-column
        prop="id"
        :label="$t('v520.taskId')"
        width="80"
      >
      </el-table-column>
      <el-table-column
        prop="group_name"
        label="群名称"
        width="140"
      >
      </el-table-column>
      <el-table-column
        prop="target"
        label="目标群组"
        width="120"
      >
        <template slot-scope="scope">
          {{scope.row.target}}<br />
          <template v-if="scope.row.country != null && scope.row.country != '' ">
            <img style="width: 20px;height: 15px;" :src="'https://cdn.staticfile.org/flag-icons/6.7.0/flags/4x3/'+scope.row.country.toLowerCase()+'.svg'" />
            <el-tag effect="plain">{{ scope.row.country }}</el-tag>
          </template>
          <template v-else>
            <el-tag type="info" effect="plain">无指定国</el-tag>
          </template>
          <div>
            <a-tag v-if="scope.row.warn == 1" color="#ff4d4f">风控</a-tag>
            <a-tag v-if="scope.row.warn == 2" color="#ff4d4f">管理员风控</a-tag>
          </div>
        </template>
      </el-table-column>
      <el-table-column
        prop="status"
        :label="$t('v520.taskState')"
        width="145"
      >
        <template slot-scope="scope">
          <el-tag v-if="scope.row.status == -2" type="info"><i class="el-icon-loading"></i>定时待启动</el-tag>
          <el-tag v-if="scope.row.status == -1"><i class="el-icon-loading"></i>初始创建中</el-tag>
          <el-tag v-if="scope.row.status == 0"><i class="el-icon-loading"></i>执行中</el-tag>
          <el-tag v-if="scope.row.status == 1" type="success"><i class="el-icon-circle-check"></i>执行完成</el-tag>
          <template v-if="scope.row.is_step == 1">
            <br />
            <el-tag type="warning" effect="plain">分步</el-tag>
          </template>
          <div v-if="scope.row.success > 0 && scope.row.admin_finish == 0">
            <a-tag color="#ff4d4f">GM失败</a-tag>
          </div>
          <div v-if="scope.row.status == -2" style="font-size: 7px;color: #999;">
            {{scope.row.start_time}}
          </div>
        </template>
      </el-table-column>
      <el-table-column
        prop="success"
        label="成功完成群组"
        width="110"
      >
        <template slot-scope="scope">
            <span style="font-size: 16px;color: #1e7e34;font-weight: 700;">
              {{scope.row.success}}
            </span>
        </template>
      </el-table-column>
      <el-table-column
        prop="fail"
        label="失败群组数"
        width="110"
      >
        <template slot-scope="scope">
            <span style="font-size: 16px;color: #bd2130;font-weight: 700;">
              {{scope.row.fail}}
            </span>
        </template>
      </el-table-column>
      <el-table-column
        prop="execute_num"
        label="执行次数"
        width="120"
      >
        <template slot-scope="scope">
            <span style="font-size: 16px;color: #00CCCC;font-weight: 700;">
              {{scope.row.execute_num}}
            </span>
        </template>
      </el-table-column>
      <el-table-column
        prop="createtime"
        :label="$t('v520.createTime')"
        width="160"
      >
      </el-table-column>
      <el-table-column
        prop="finish_time"
        label="任务完成时间"
        width="160"
      >
      </el-table-column>
      <el-table-column
        fixed="right"
        :label="$t('v520.operate')"
        width="330"
      >
        <template slot-scope="scope">
          <router-link :to="'/wa_task/pull_info/'+scope.row.id">
            <el-button type="primary" size="mini" v-if="scope.row.status == 0 || scope.row.status == -1 || scope.row.status == 1 " plain>
              <i class="wshub wshub-liebiaoshitu"></i>
              详情
            </el-button>
          </router-link>
          &nbsp;&nbsp;&nbsp;
          <el-button size="mini" @click="downloadData(scope.row.did)" plain>
            <i class="wshub wshub-download"></i>
            料子
          </el-button>

          <el-button type="danger" size="mini" @click="stopTask(scope.row.id)" v-if="scope.row.status == 0 || scope.row.status == -1 || scope.row.status == -2" plain>
            <i class="wshub wshub-guanbi2"></i>
            停止
          </el-button>

          <el-button type="success" size="mini" v-if="scope.row.status == 1 && scope.row.success > 0" @click="exportResult(scope.row.id)"  plain>
            <i class="wshub wshub-a-kuozhanicon_huaban1fuben5"></i>
            回执
          </el-button>

          <el-button type="warning" size="mini" @click="loadTask(scope.row.id)" v-if="scope.row.status == 1" plain>
            <i class="wshub wshub-RectangleCopy6"></i>
            重试
          </el-button>

        </template>
      </el-table-column>
    </el-table>
    <div style="width: 100%;text-align: right;padding-right: 20px;">
      <el-pagination
        background
        layout="prev, pager, next"
        :page-size="20"
        :current-page.sync="queryList.page"
        :total="total"
        @current-change="getDataList()"
      >
      </el-pagination>
    </div>

    <el-dialog
      title="新增拉群任务"
      :visible.sync="dialogVisible"
      width="60%"
      :before-close="handleClose">
      <el-radio-group v-model="type" size="small" style="margin: 10px;">
<!--        <el-radio-button disabled :label="0">群拉群(停用)</el-radio-button>-->
<!--        <el-radio-button :label="1">采集完的群成员拉群</el-radio-button>-->
        <el-radio-button :label="2">自定义用户</el-radio-button>
      </el-radio-group>
      <el-alert
        title="群链提示"
        v-if="type == 0"
        type="info"
        description="群链以 chat.whatsapp.com/xxxx 为群链格式,同时拉取多个来源至目标群 每行一个"
        show-icon>
      </el-alert>
      <el-input v-if="type == 0" type="textarea" :rows="9" v-model="links"  ></el-input>
      <el-button v-if="type == 0" type="primary" @click="txtbtn">
        <i class="wshub wshub-wendang"></i>
        导入群链txt
      </el-button>
      <input type="file" @change="loadTextFromFile" id="txt" style="display:none" />

      <el-row :gutter="20">
        <el-col :xs="24" :sm="24" :md="24" :lg="12">
          <div style="margin-top: 10px;">
            <span style="font-weight: 700;margin-right: 5px;width: 80px;display: inline-block;">任务国</span>
            <el-select v-model="country" @change="checkPhones" style="width: 220px;" filterable clearable  placeholder="请选择国家">
              <el-option
                v-for="item in instanceCountry"
                :key="item.country_code"
                :label="item.country+item.country_cn+item.country_code"
                :value="item.country_code">
                  <span style="float: left">
                    <img style="width: 20px;height: 15px;" :src="'https://cdn.staticfile.org/flag-icons/6.7.0/flags/4x3/'+item.country_code_lower+'.svg'" />
                    {{ item.country }}-{{ item.country_cn }}
                  </span>
                <span style="float: right; color: #8492a6; font-size: 13px">{{ item.country_code }}</span>
              </el-option>
            </el-select>
          </div>
        </el-col>
      </el-row>

      <el-row :gutter="20">
        <el-col :xs="24" :sm="24" :md="24" :lg="12">
          <div style="margin-top: 10px;">
            <span style="font-weight: 700;margin-right: 5px;width: 80px;display: inline-block;">群名称</span>
            <el-input  v-model="group_name"  style="width: 220px;"></el-input>
          </div>
        </el-col>
        <el-col :xs="24" :sm="24" :md="24" :lg="12">
          <div style="margin-top: 10px;">
            <span style="font-weight: 700;margin-right: 5px;width: 80px;display: inline-block;">群描述</span>
            <el-input  v-model="description"  style="width: 300px;"></el-input>
          </div>
        </el-col>
      </el-row>
      <div style="margin-top: 15px;">
        <span style="font-weight: 700;margin-right: 5px;width: 90px;display: inline-block;">管理员手机号</span>
        (需要国际区号)
        <el-input type="textarea" :rows="5" v-model="admins" placeholder="例:8613131313131"  ></el-input>
      </div>
      <div style="margin-top: 15px;">
        <span style="font-weight: 700;margin-right: 5px;width: 90px;display: inline-block;">水军号</span>
        (需要国际区号)
        <el-input type="textarea" :rows="5" v-model="navy" placeholder="例:8613131313131"  ></el-input>
      </div>
      <el-row :gutter="20">
        <el-col :xs="24" :sm="24" :md="24" :lg="12">
          <div style="margin-top: 10px;">
            <span style="font-weight: 700;margin-right: 5px;">群头像</span>
            <el-upload
              class="avatar-uploader"
              action="/api/uploadAvatar"
              :headers="headers"
              :show-file-list="false"
              :on-success="handleAvatarSuccess">
              <img v-if="imageUrl" :src="imageUrl" class="avatar">
              <i v-else class="el-icon-plus avatar-uploader-icon"></i>
            </el-upload>
          </div>
        </el-col>
        <el-col :xs="24" :sm="24" :md="24" :lg="12">
          <div style="margin-top: 15px;">
            <span style="font-weight: 700;margin-right: 5px;width: 100px;display: inline-block;">是否禁言</span>
            <el-switch
              v-model="can_speak"
              active-color="#13ce66"
              inactive-color="#ff4949"
              active-text="仅管理发言"
              inactive-text="任何人可发言"
            >
            </el-switch>
          </div>
        </el-col>
      </el-row>

      <el-row :gutter="20" style="margin-top: 15px;margin-bottom: 15px;" v-if="isShowAdminNum">
<!--        <el-col :xs="24" :sm="24" :md="24" :lg="12">-->
<!--          <div style="margin-top: 10px;">-->
<!--            <span style="font-weight: 700;margin-right: 5px;width: 120px;display: inline-block;">拉群账户数量</span>-->
<!--            <el-input type="number" :min="1" v-model="pull_admin_num"  style="width: 120px;"></el-input>-->
<!--          </div>-->
<!--        </el-col>-->
        <el-col :xs="24" :sm="24" :md="24" :lg="12">
          <div style="margin-top: 10px;">
            <span style="font-weight: 700;margin-right: 5px;width: 120px;display: inline-block;">单次拉人数量</span>
            <el-input  type="number" :min="1" v-model="pull_admin_account_num"  style="width: 120px;"></el-input>
          </div>
        </el-col>
        <el-col :xs="24" :sm="24" :md="24" :lg="12">
        <div style="margin-top: 10px;">
          外部群
          <el-input  v-model="old_group_url"  style="width: 220px;"></el-input>
        </div>
        </el-col>
      </el-row>

      <el-row :gutter="20" v-if="isShowBatch" style="margin-top: 15px;margin-bottom: 15px;">
        <el-col :xs="24" :sm="24" :md="24" :lg="12">
          <div style="margin-top: 10px;">
            <span style="font-weight: 700;margin-right: 5px;width: 120px;display: inline-block;">单群料子数量</span>
            <el-input-number style="width: 140px;" v-model="pull_split_num" @change="calcRow" :min="1" :step="5"></el-input-number>
          </div>
          <div style="margin-top: 10px;">
            <span style="font-weight: 700;margin-right: 5px;width: 120px;display: inline-block;">群启始编号</span>
            <el-input-number style="width: 140px;" v-model="startNo"  :min="0" ></el-input-number>
            <div style="font-size: 8px;color: #888;">0为不设编号</div>
          </div>
        </el-col>
      </el-row>

      <el-radio-group  v-model="start_type" v-if="tryTaskId == 0" @change="changeStartType" size="small">
        <el-radio-button :label="0">即时启动</el-radio-button>
        <el-radio-button :label="1">定时启动</el-radio-button>
      </el-radio-group>

      <el-row :gutter="20" v-if="start_type == 1 && tryTaskId == 0" style="margin-top: 15px;margin-bottom: 15px;">
        <el-col :xs="24" :sm="24" :md="24" :lg="12">
          <div style="margin-top: 10px;">
            <span style="font-weight: 700;margin-right: 5px;width: 120px;display: inline-block;">启动时间</span>
            <el-date-picker
              v-model="start_time"
              value-format="yyyy-MM-dd HH:mm:ss"
              type="datetime"
              placeholder="选择启动时间">
            </el-date-picker>
          </div>
        </el-col>
      </el-row>

      <el-alert
        title="用户账户"
        v-if="type == 2"
        type="info"
        description="手机号需要包含区号 例如 +8613111111111 或 8613111111111 每行一个"
        show-icon>
      </el-alert>
      <div>
        料子数据行数
        <el-tag style="font-size: 16px;font-weight: 700;" type="primary" effect="dark">{{phoneRow}}</el-tag>
        <span v-if="pull_split_num > 0"> 预计切分为<el-tag style="font-size: 16px;font-weight: 700;" type="danger" effect="dark">{{groupNum}}</el-tag>个群</span>
        &nbsp;&nbsp;&nbsp;
        <el-button type="primary" size="mini" @click="removeDuplicates()" >
          <i class="wshub wshub-click"></i>
          一键料子去重
        </el-button>
      </div>
      <el-input v-if="type == 2" type="textarea" :rows="9" v-model="links" @input="calcRow" @change="checkPhones"  ></el-input>
      <el-button v-if="type == 2" type="primary" @click="txtbtn">
        <i class="wshub wshub-wendang"></i>
        导入账户txt
      </el-button>
      <input type="file" @change="loadTextFromFile" id="txt" style="display:none" />

      <div v-if="type == 1">
        来源任务
        <el-select  v-model="sourceTask" placeholder="请选择采集群成员的任务">
          <el-option
            v-for="item in options"
            :key="item.value"
            :label="item.label"
            :value="item.value">
          </el-option>
        </el-select>
      </div>

      <div style="margin-top: 10px;display: none;">
        拉入的群
        <el-input  v-model="target"  style="width: 220px;"></el-input>
      </div>

      <span slot="footer" class="dialog-footer">
        <el-button @click="handleClose">取 消</el-button>
        <el-button type="primary" @click="create()">确 定</el-button>
      </span>
    </el-dialog>

  </div>
</template>

<script>
import { getList,create,stop,loadTaskData,filterPhone,makeOutputKey } from '@/api/wa_pull'
import {getAllTask} from '@/api/wa_collection'
import { getToken } from '@/utils/auth'
import { getConfigCountryList } from '@/api/common'

export default {
  name: 'wa_pull',
  created() {
    getAllTask().then(res => {
      if(res.code == 0){
        this.options = res.data;
      }else{
        this.$notify.error({title:'加载数据失败',message:'加载已完成的采集群成员任务数据失败,请刷新页面'});
      }
    });
    getConfigCountryList().then(res => {
      if(res.code == 0){
        this.instanceCountry = res.data;
      }
    })
    this.getDataList();
  },
  data() {
    return {
      baseUrl:process.env.VUE_APP_BASE_API,
      fullscreenLoading:false,
      total: 0,
      type:2,
      queryList: {
        limit: 20,
        page: 1
      },
      isShowAdminNum:false,
      isShowBatch:false,
      instanceCountry:[],
      headers:{sid:getToken()},
      options:[],
      dialogVisible:false,
      links:'',
      sourceTask:null,
      target:'',
      admins:'',
      can_speak:false,
      group_name:'',
      imageUrl:'',
      avatar:'',
      description:'',
      old_group_url:'',
      tryTaskId:0,
      navy:'',
      country:'',
      tableData: [],
      pull_admin_num:0,
      pull_admin_account_num:0,
      pull_split_num:0,
      phoneRow:0,
      groupNum:1,
      selectIds:[],
      startNo:0,
      dl_t:'',
      start_type:0,
      start_time:'',
    }
  },
  methods: {
    getDataList() {
      const loading = this.$loading({
        lock: true,
        text: this.$t('v520.getting'),
        spinner: 'el-icon-loading',
        background: 'rgba(0, 0, 0, 0.7)'
      })
      getList(this.queryList).then(res => {
        loading.close()
        this.tableData = res.data.rows
        this.total = res.data.total
        this.dl_t = res.data.dl_t;
      }).catch(e => {
        loading.close()
        this.$message.error('请求失败')
      })
    },
    changeStartType(val){
      if(this.start_type == 0){
        this.start_time = '';
      }
    },
    showCreate(val){
      this.links = '';
      this.type = 2;
      if(val == 1){
        //普通建群
        this.pull_admin_num = 0;
        this.pull_admin_account_num = 0;
        this.pull_split_num = 0;
        this.startNo = 0;
        this.isShowAdminNum = false;
      }else if(val == 2 ){
        //分布拉群
        this.isShowAdminNum = true;
        this.pull_admin_num = 1;
        this.pull_admin_account_num = 50;
        this.pull_split_num = 0;
        this.startNo = 0;
      }
      else if(val == 3){
        //普通批量拉群
        this.pull_admin_num = 0;
        this.pull_admin_account_num = 0;
        this.isShowBatch = true;
        this.pull_split_num = 200;
        this.startNo = 0;
      }
      else{
        //分布批量拉群
        this.isShowAdminNum = true;
        this.pull_admin_num = 1;
        this.pull_admin_account_num = 50;
        this.isShowBatch = true;
        this.pull_split_num = 200;
        this.startNo = 0;
      }
      this.dialogVisible = true;
    },
    handleClose(){
      this.links = '';
      this.type = 2;
      this.isShowAdminNum = false;
      this.isShowBatch = false;
      this.dialogVisible = false;
      // this.can_speak = false;
      // this.group_name = '';
      // this.avatar = '';
      // this.imageUrl = '';
      // this.admins = '';
      // this.description = '';
      this.tryTaskId = 0;
      this.calcRow();
    },
    calcRow(){
      if(this.links == ''){
        var row = [];
      }else{
        var row = this.links.split("\n");
      }
      this.phoneRow = row.length;
      if(this.phoneRow == 0){
        this.groupNum = 0;
        return;
      }

      if(this.pull_split_num > 0){
        this.groupNum =  Math.ceil(this.phoneRow/this.pull_split_num);
      }
    },
    create(){

      if(this.group_name == '' || this.admins == ''){
        this.$notify.error({title:'创建失败',message:'请输入群名称及管理员'});
        return;
      }


      if(this.links == '' && this.type == 0){
        this.$notify.error({title:'创建失败',message:'请输入要群拉群的 来源群'});
        return;
      }

      if((this.sourceTask == null || this.sourceTask == '' || this.sourceTask == 0 ) && this.type == 1){
        this.$notify.error({title:'创建失败',message:'请选择来源采集群成员任务'});
        return;
      }

      this.fullscreenLoading = true;

      var data = {
        target:this.target,
        admins:this.admins,
        group_name:this.group_name,
        start_time:this.start_time
      };

      if(this.type == 0){
        var links = this.links.split('\n');
        var newLinks = links.map(val => {
          var tmp = val;
          tmp.replace("https://",'');
          return tmp.replace("\r","");
        });
        data.links = newLinks.join(',');
      }
      else if(this.type == 2){
        var links = this.links.split('\n');
        var newLinks = links.map(val => {
          var tmp = val;
          tmp.replace("https://",'');
          return tmp.replace("\r","");
        });
        data.links = newLinks.join(',');
        data.customize = 1;
        data.can_speak = this.can_speak?'0':'1';
        data.avatar = this.avatar;
        data.description = this.description;
        data.navy = this.navy;
        data.country = this.country;
        data.pull_admin_num = this.pull_admin_num;
        data.pull_admin_account_num = this.pull_admin_account_num;
        data.pull_split_num = this.pull_split_num;
        data.old_group_url = this.old_group_url;
        if(this.tryTaskId != 0){
          data.try_id = this.tryTaskId;
        }
        data.start_no = this.startNo;
      }
      else{
        data.from = this.sourceTask;
      }

      create(data).then(res => {
        this.fullscreenLoading = false;
        if(res.code == 0){
          this.handleClose();
          this.$notify.success({title:'创建成功',message:'您的任务即将开始执行'});
          this.getDataList();
        }else{
          this.$message.error(res.msg);
        }
      }).catch( err => {
        this.fullscreenLoading = false;
        this.$notify.success({title:'创建失败',message:'发起请求失败,请重试'});
      });

    },
    txtbtn() {
      document.getElementById("txt").click();
    },
    loadTextFromFile(e) {
      const file = e.target.files[0];
      let name = file.name.split(".").splice(-1).toString();
      if (name !== "txt") {
        this.$message.success("文件类型错误,请重新选择文件");
        return;
      }
      const reader = new FileReader();
      if (typeof FileReader === "undefined") {
        alert("您的浏览器不支持FileReader");
      }
      reader.onload = (e) => this.$emit("load", this.dealNum(e.target.result));
      reader.readAsText(file, "utf-8");
    },
    dealNum(item) {
      this.links = item;
      this.calcRow();
    },
    stopTask(id){
      stop({id}).then(res => {
        if(res.code == 0){
          this.$message.success('停止成功');
          this.getDataList();
        }else{
          this.$message.error(res.msg);
        }
      });
    },
    handleAvatarSuccess(res,file){
      if(res.code == 0){
        this.imageUrl = '/media_file/'+res.data.file;
        this.avatar = res.data.file;
      }else{
        this.imageUrl = '';
      }
    },
    downloadData(taskId){
      this.$confirm('是否需要包含管理员?', '提示', {
        confirmButtonText: '包含管理员',
        cancelButtonText: '不包含管理员',
        type: 'warning',
        distinguishCancelAndClose:true
      }).then(() => {
        window.open(this.baseUrl+'/wa_pull/downloadPullData?task_id='+taskId+'&admin=1&dl_t='+this.dl_t);
      }).catch((action) => {
        if(action == 'cancel'){
          window.open(this.baseUrl+'/wa_pull/downloadPullData?task_id='+taskId+'&dl_t='+this.dl_t);
        }else{
          this.$message.info('你取消了下载');
        }
      });
    },
    loadTask(taskId){
      const loading = this.$loading({
        lock: true,
        text: this.$t('v520.getting'),
        spinner: 'el-icon-loading',
        background: 'rgba(0, 0, 0, 0.7)'
      })
      //加载任务数据以便重建
      loadTaskData({task_id:taskId}).then(res=>{
        loading.close();
        if(res.code == 0){
            this.tryTaskId = taskId;
            this.admins = res.data.admins;
            this.navy  = res.data.navy;
            this.group_name = res.data.name;
            this.can_speak = res.data.can_speak;
            this.imageUrl = res.data.avatar_show_img;
            this.avatar = res.data.avatar;
            this.links = res.data.phone_numbers;
            this.description = res.data.description;
            this.country = res.data.country;
            this.pull_admin_num = res.data.pull_admin_num;
            this.pull_admin_account_num = res.data.pull_admin_account_num;
            if(this.pull_admin_num > 0){
              this.isShowAdminNum = true;
            }else{
              this.isShowAdminNum = false;
            }
            this.calcRow();
            this.dialogVisible = true;
        }else{
          this.$message.error(res.msg);
        }
      }).catch(err=>{
        loading.close();
        this.$message.error('请求失败,请重试');
      });
    },
    checkPhones(){
      if(this.country == '' || this.links == ''){return;}
      var row = this.links.split("\n");
      let _this = this;
      filterPhone({links:row.join(','),country:this.country}).then(res=>{
        if(res.code == 0){
          if(res.data.check == 2){
            this.$confirm('料子中有'+res.data.invalid_num+'个不符合所选国家的号码,是否自动清除?', '提示', {
              confirmButtonText: '确定',
              cancelButtonText: '取消',
              type: 'warning'
            }).then(() => {
              let r = row.filter(function(phone){
                if(res.data.result.indexOf(phone) !== -1){
                  return false;
                }
                return true;
              });
              _this.links = r.join("\n");
              _this.calcRow();
            }).catch(() => {});
          }
        }
      })
    },
    handleSelectionChange(val) {
      var ids = [];
      if(val != null && val.length > 0){
        val.forEach((item) =>{
          ids.push(item.did);
        })
      }
      this.selectIds = ids;
    },
    batchReceipt(){
      if(this.selectIds.length <= 0){
        this.$message.error('无勾选的拉群任务');
        return;
      }
      this.exportResult(this.selectIds);
    },
    batchPullData(){
      if(this.selectIds.length <= 0){
        this.$message.error('无勾选的拉群任务');
        return;
      }
      window.open('/api/wa_pull/downloadPullData?task_id='+this.selectIds.join(',')+'&dl_t='+this.dl_t);
    },
    exportResult(id){
      let ids = id;
      if(id instanceof Array){
        ids = id.join(',');
      }
      makeOutputKey({id:ids}).then(res=>{
        if(res.code == 0){
          window.open('/api/wa_pull/exportPullResult?download='+res.data.key);
        }else{
          this.$message.error(res.msg);
        }
      }).catch(err =>{
        this.$message.error('发起请求失败,请重试!');
      });
    },
    removeDuplicates(){
      var links = this.links.split('\n');
      var result = Array.from(new Set(links));
      this.links = result.join("\n");
      this.calcRow();
      this.$notify.success({title:'操作成功',message:'料子数据已去重!'});
    }
  }
}
</script>

<style lang="scss" scoped>
.dashboard-editor-container {
  background-color: #FFF;
  min-height: 100vh;
  padding: 40px 40px 0px;

  .pan-info-roles {
    font-size: 12px;
    font-weight: 700;
    color: #333;
    display: block;
  }

  .info-container {
    position: relative;
    margin-left: 190px;
    height: 150px;
    line-height: 200px;

    .display_name {
      font-size: 48px;
      line-height: 48px;
      color: #212121;
      position: absolute;
      top: 25px;
    }
  }
}
</style>
<style>
.avatar-uploader .el-upload{
  border: 1px dashed #666666 !important;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}
.avatar-uploader .el-upload:hover {
  border-color: #409EFF;
}
.avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: 128px;
  height: 128px;
  line-height: 128px;
  text-align: center;
}
.avatar {
  width: 128px;
  height: 128px;
  display: block;
}
</style>
